package com.dxg.msns.music.controller;

import com.dxg.msns.music.pojo.Playlist;
import com.dxg.msns.music.service.PlaylistFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/music/playlist/favorite")
public class PlaylistFavoriteController {

    @Autowired
    private PlaylistFavoriteService favoriteService;

    @PostMapping("/add")
    public ResponseEntity<?> addFavorite(@RequestParam String userId, @RequestParam String playlistId) {
        boolean success = favoriteService.favoritePlaylist(userId, playlistId);
        return success ? ResponseEntity.ok("收藏成功") : ResponseEntity.status(500).body("收藏失败");
    }

    @PostMapping("/remove")
    public ResponseEntity<?> removeFavorite(@RequestParam String userId, @RequestParam String playlistId) {
        boolean success = favoriteService.unfavoritePlaylist(userId, playlistId);
        return success ? ResponseEntity.ok("取消收藏成功") : ResponseEntity.status(500).body("取消失败");
    }

    @GetMapping("/list")
    public ResponseEntity<?> listFavorites(@RequestParam String userId) {
        List<Playlist> ids = favoriteService.getFavoritePlaylistIds(userId);
        return ResponseEntity.ok(ids);
    }

    @GetMapping("/isFavorited")
    public ResponseEntity<?> isFavorited(@RequestParam String userId,@RequestParam String playlistId) {
        Boolean result = favoriteService.isFavorited(userId,playlistId);
        return ResponseEntity.ok(result);
    }
}